package xin.mashibo.pattern.builder;

/**
 * 执行Builder模式的主类
 *
 * @author MaShibo
 * 日期 :  2019/1/23
 */
public class Main {

    public static void main(String[] args) {
        if (args.length != 1) {
            usage();
            System.exit(0);
        }
        String sign = args[0];
        if ("plain".equals(sign)) {
            TextBuilder textBuilder = new TextBuilder();
            Director director = new Director(textBuilder);
            director.construct();
            String result = textBuilder.getResult();
            System.out.println(result);
        } else if ("html".equals(sign)) {
            HTMLBuilder htmlBuilder = new HTMLBuilder();
            Director director = new Director(htmlBuilder);
            director.construct();
            String fileName = htmlBuilder.getResult();
            System.out.println(fileName + "文件编写完成。");
        } else {
            usage();
            System.exit(0);
        }
    }

    private static void usage() {
        System.out.println("Usage: java Main plain  编写纯文本文档");
        System.out.println("Usage: java Main html   编写HTML文档");
    }
}
